package com.atguigu.gulimall.search.web;

import com.atguigu.gulimall.search.service.MallSearchService;
import com.atguigu.gulimall.search.vo.SearchParam;
import com.atguigu.gulimall.search.vo.SearchResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Controller
public class IndexController {

    @Resource
    private MallSearchService mallSearchService;

    @RequestMapping({"/list.html","/index.html","/"})
    public String list(SearchParam searchParam, Model model, HttpServletRequest request) throws IOException {
        String queryString = request.getQueryString();
        searchParam.setQueryString(queryString);
        SearchResult result = mallSearchService.search(searchParam);
        model.addAttribute("result",result);
        return "list";
    }

}
